package com.woniu.dating.mapper;

import com.woniu.dating.pojo.DatingHobby;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniu.dating.vo.ConcernVO;
import com.woniu.dating.vo.DatingLoginVO;
import com.woniu.dating.vo.RecommendVO;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 玖柒
 * @since 2023-05-20
 */
public interface DatingHobbyMapper extends BaseMapper<DatingHobby> {


    /**
     * 按照关注度从高到底排序。相亲兴趣
     * @return
     */
    @Select("SELECT dh.id, dh.age, dh.user_id, dh.nickname, dh.gender, dh.city, dh.signature, dh.avatar, dh.photo, dh.height, dh.mobile, dh.career, dh.create_time, dh.update_time, dc.concernNum FROM t_dating_hobby dh INNER JOIN (SELECT user_id,COUNT(user_id) concernNum FROM t_dating_concern GROUP BY user_id) dc ON dc.user_id = dh.`user_id` ORDER BY dc.concernNum")
    @ResultType(RecommendVO.class)
    List<RecommendVO> listRecommendInfo();

    /**
     * 同乡。按照关注度排序
     * @param city
     * @return
     */
    @Select("SELECT dh.id, dh.age, dh.user_id, dh.nickname, dh.gender, dh.city, dh.signature, dh.avatar, dh.photo, dh.height, dh.mobile, dh.career, dh.create_time, dh.update_time, dc.concernNum FROM t_dating_hobby dh INNER JOIN (SELECT user_id,COUNT(user_id) concernNum FROM t_dating_concern GROUP BY user_id) dc ON dc.user_id = dh.`user_id` where dh.city = #{city} ORDER BY dc.concernNum")
    @ResultType(RecommendVO.class)
    List<RecommendVO> listFellow(String city);

    /**
     * 找男友
     * @param datingBoy
     * @return
     */
    @Select("SELECT dh.id, dh.age, dh.user_id, dh.nickname, dh.gender, dh.city, dh.signature, dh.avatar, dh.photo, dh.height, dh.mobile, dh.career, dh.create_time, dh.update_time, dc.concernNum FROM t_dating_hobby dh INNER JOIN (SELECT user_id,COUNT(user_id) concernNum FROM t_dating_concern GROUP BY user_id) dc ON dc.user_id = dh.`user_id` where dh.gender = #{datingBoy} ORDER BY dc.concernNum")
    @ResultType(RecommendVO.class)
    List<RecommendVO> listBoy(String datingBoy);

    /**
     * 找女友
     * @param datingGirl
     * @return
     */
    @Select("SELECT dh.id, dh.age, dh.user_id, dh.nickname, dh.gender, dh.city, dh.signature, dh.avatar, dh.photo, dh.height, dh.mobile, dh.career, dh.create_time, dh.update_time, dc.concernNum FROM t_dating_hobby dh INNER JOIN (SELECT user_id,COUNT(user_id) concernNum FROM t_dating_concern GROUP BY user_id) dc ON dc.user_id = dh.`user_id` where dh.gender = #{datingBoy} ORDER BY dc.concernNum")
    @ResultType(RecommendVO.class)
    List<RecommendVO> listGirl(String datingGirl);

    /**
     * 按照用户id查询
     * @param userId
     * @return
     */
    @Select("select id, age, user_id, nickname, gender, city, signature, avatar, photo, height, mobile, career from t_dating_hobby where user_id = #{userId}")
    @ResultType(DatingHobby.class)
    DatingHobby getDatingHobby(Integer userId);

    /**
     * 根据用户id获取相亲兴趣信息
     * @param userId
     * @return
     */
    @Select("SELECT dh.id, dh.age, dh.user_id, dh.nickname, dh.gender, dh.city, dh.signature, dh.avatar, dh.photo, dh.height, dh.mobile, dh.career, dh.create_time, dh.update_time, dc.concernNum FROM t_dating_hobby dh INNER JOIN (SELECT user_id,COUNT(user_id) concernNum FROM t_dating_concern GROUP BY user_id) dc ON dc.user_id = dh.`user_id` where dh.user_id = #{userId} ORDER BY dc.concernNum")
    @ResultType(RecommendVO.class)
    RecommendVO getDatingHobbyByUserId(Integer userId);

    /**
     * 根据id,获取concer信息
     * @param userId
     * @return
     */
    @Select("select user_id, nickname, gender, age, city, avatar from t_dating_hobby where user_id = #{userId}")
    @ResultType(ConcernVO.class)
    ConcernVO getDatingConcernVO(Integer userId);

    /**
     * 手机号获取用户信息
     * @param mobile
     * @return
     */
    @Select("select id, age, user_id, nickname, gender, city, signature, avatar, photo, height, mobile, career, create_time from t_dating_hobby where mobile = #{mobile}")
    @ResultType(DatingLoginVO.class)
    DatingLoginVO getDatingHobbyByMobile(String mobile);
}
